﻿using Lottery.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lottery.Real
{
    public class CustomPredictor : IPredictor
    {
        public IEnumerable<ICombination> Predict(IGameHistory gameHistory)
        {
            var orderedHistory = gameHistory.History.OrderByDescending(gh => gh.Date).Take(6);
            var hitCount = new Dictionary<int, int>();
            
            foreach (var history in orderedHistory)
            {
                foreach (var number in history.NumberSet.Numbers)
                {
                    if (!hitCount.ContainsKey(number))
                    {
                        hitCount.Add(number, 1);
                    }
                    else
                    {
                        hitCount[number] = hitCount[number] + 1;
                    }
                }
            }

            var selectedNumbers = hitCount.OrderBy(hc => hc.Value).Select(hc => hc.Key).Take(6).ToList();

            return new List<ICombination>() { new Combination() { Numbers = selectedNumbers } };
        }
    }
}
